#include "Subject.h"

Subject::Subject() {}

void Subject::registerObserver(Observer* observer) {
	this->observers.push_back(observer);
}

void Subject::unregisterObserver(Observer* observer) {
	vector <Observer*> aux;
	
	for (std::vector<Observer*>::size_type i = 0; i != this->observers.size(); i++) {

		if (!(this->observers[i]->getId() == observer->getId())) {
			aux.push_back(this->observers[i]);
		}		
	}
	this->observers.clear();
	this->observers = aux;
}

void Subject::notifyObservers() {
	for (std::vector<Observer*>::size_type i = 0; i != this->observers.size(); i++) {
		this->observers[i]->notify();
	}
}

void Subject::setObservers(vector <Observer*> observers) {
	this->observers = observers;
}

vector <Observer*> Subject::getObservers() {
	return this->observers;
}

Subject::~Subject() {}
